#ifndef _MAIN_H_
#define _MAIN_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Time.h"
#include "IO.h"
#include "308.h"
#include "user.h"
#include "Shrink.h"
#include "Char.h"
#include "uart.h"

typedef unsigned char	uchar;
typedef unsigned int	uint;
typedef unsigned long	uint32;

#define ESP_NVS_TAG  	"NVS_DEMO"
#define USER_TAG  	    "USER_DEMO"
#define SPP_TAG  	    "SPP_DEMO"
#define BT_SPP_TAG  	"BT_SPP_DEMO"
#define BLE_SPP_TAG  	"BLE_SPP_DEMO"
#define WIFI_TAG		"WIFI_DEMO"
#define WIFI_AP_TAG 	"WIFI_AP_DEMO"
#define WIFI_STA_TAG 	"WIFI_STA_DEMO"
#define OTA_UPGRADE_TAG "OTA_UPGRADE_DEMO"

#define BTMAC_TAG 		"EVE_"

#define NVS_key_Set 	"Set_NVS"
#define NVS_key_InkC 	"InkC_NVS"
#define NVS_key_InkP 	"InkP_NVS"
#define NVS_key_PicLen 	"PicLen_NVS"
#define NVS_key_Counter "Counter_NVS"

#define PIN_NUM_MISO 	19
#define PIN_NUM_MOSI 	23
#define PIN_NUM_CLK  	18
#define PIN_NUM_CS   	5

#define spp_sprintf(s,...)         sprintf((char*)(s), ##__VA_ARGS__)
#define SPP_DATA_MAX_LEN           (512)
#define SPP_CMD_MAX_LEN            (20)
#define SPP_STATUS_MAX_LEN         (20)
#define SPP_DATA_BUFF_MAX_LEN      (2*1024)

char	*ota_upgrade_url_val;			//用于存储ota升级的URL值
uchar 	RxBuf[100000];					//接收数据指针

//赋初始值
typedef struct{
	uint32 Ble_WriteHdl;				//BLE发送句柄
	uint32 Ble_gatts_if;
	uint32 Ble_conn_id;
}User_parameter_val_t;//用户参数值

User_parameter_val_t UserParm_val;//用户参数

//赋初始值
typedef struct{
	uchar	sta_IP_val[4];				//STA模式的IP值
	uchar	sta_mac_val[6];				//STA模式的MAC值
}user_preference_val_t;		//用户参数

user_preference_val_t user_prefer_val;

//赋初始值
struct {
	//esp_launch_wifi_stu_flg标志位主要是防止esp_netif_create_default_wifi_sta函数多次启动(机器会复位)或者未开启
	uint esp_launch_wifi_stu_flg : 2;	//0:机器未开机   	1:机器已开机AP或STA启动			 2:机器一开机AP和STA都启动过
	uint wifi_launch_ap_sta_flg : 2;	//0:机器启动		1:AP启动		2:STA启动
	uint wifi_stu_type_flg : 1;			//0:AP模式  		1:STA模式
	uint ota_start_upgrade_flg : 1;		//0:未开启ota		1:开启ota
	uint sta_to_ap_restart : 1;			//0:未重启			1:切回AP并重启
}esp_pb_stu_flg;	//公共变量使用位域

enum{
    SPP_IDX_SVC,

	SPP_IDX_SPP_COMM_RECV_CHAR,
    SPP_IDX_SPP_COMM_RECV_VAL,
    
	SPP_IDX_SPP_REPLY_RECV_CHAR,
    SPP_IDX_SPP_REPLY_RECV_VAL,

	SPP_IDX_SPP_DATA_RECV_CHAR,
    SPP_IDX_SPP_DATA_RECV_VAL,

    SPP_IDX_NB,
};

//赋初始值
struct {
	uint PrintContinue : 1;				
	
}esp_tim_run_flg;	//定时器运行变量 0:无定时器    		1:开启定时

extern uint8_t OTAupgrade_Version;
extern uint8_t  MCU_ON_flag;
extern uint8_t  MCU_OFF_flag;
extern uint8_t  Debug_set;
extern uint8_t  ChargingStart;
extern uint8_t  SystemLaunch;

extern uint32_t data_length;
extern uint8_t ADC_LowPowerAlarm,PowerLED,adcTimeRead;

extern uint8_t testFlag;

void SendToApp(uint8_t len,uchar* val);
void PrintfCmd(uchar num,uint8_t* data);
void FLASH_ReadByte(void);
void adc_Refresh_handler(void);
esp_err_t esp_nvs_read_handler(char* nvs_key_name,void *nvs_value);
esp_err_t esp_nvs_write_handler(char* nvs_key_name,void *nvs_value,uint len);

#endif

